Conditions | 4 |
Paths | 93 |
Total Lines | 83 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | 'use strict'; |
||
3 | function decryptAES (password) { |
||
4 | |||
5 | try { |
||
6 | |||
7 | var decryptionError = String(document.getElementById('decryptionError').innerHTML); |
||
8 | var noContentError = String(document.getElementById('noContentError').innerHTML); |
||
9 | |||
10 | } catch (e) { |
||
11 | |||
12 | decryptionError = 'Incorrect Password!'; |
||
13 | noContentError = 'No content to display!'; |
||
14 | |||
15 | } |
||
16 | |||
17 | try { |
||
18 | |||
19 | let content = CryptoJS.AES.decrypt(document.getElementById('encrypt-blog').innerHTML.trim(), password); |
||
20 | content = content.toString(CryptoJS.enc.Utf8); |
||
21 | content = decodeBase64(content); |
||
22 | content = unescape(content); |
||
23 | if (content === '') { |
||
24 | |||
25 | throw new Error(noContentError); // ??? |
||
26 | |||
27 | } else { |
||
28 | |||
29 | document.getElementById('encrypt-blog').style.display = 'inline'; |
||
30 | document.getElementById('encrypt-blog').innerHTML = ''; |
||
31 | |||
32 | // Use jquery to load some js code |
||
33 | try { |
||
34 | |||
35 | $('#encrypt-blog').html(content); |
||
36 | |||
37 | // NO Style Change here |
||
38 | {callback} |
||
39 | // NO Style Change here |
||
40 | |||
41 | } catch(e) { |
||
42 | |||
43 | const errorInfo = '<p>' |
||
44 | + 'Some errors occurred, check the original file please.' |
||
45 | + 'Detailed exceptions are shown in console.' |
||
46 | + '</p>'; |
||
47 | console.error(e); |
||
48 | $('#encrypt-blog').html(errorInfo); |
||
49 | |||
50 | } |
||
51 | |||
52 | document.getElementById('hbe-security').style.display = 'none'; |
||
53 | if (document.getElementById('toc-div')) { |
||
54 | |||
55 | document.getElementById('toc-div').style.display = 'inline'; |
||
56 | |||
57 | } |
||
58 | |||
59 | } |
||
60 | |||
61 | // Call MathJax to render |
||
62 | if(typeof MathJax !== 'undefined') { |
||
63 | |||
64 | try { |
||
65 | |||
66 | MathJax.Hub.Queue( |
||
67 | ['resetEquationNumbers', MathJax.InputJax.TeX, ], |
||
68 | ['PreProcess', MathJax.Hub, ], |
||
69 | ['Reprocess', MathJax.Hub, ] |
||
70 | ); |
||
71 | |||
72 | } catch (e) { |
||
73 | |||
74 | console.log('Can\'t render with MathJax'); |
||
75 | |||
76 | } |
||
77 | |||
78 | } |
||
79 | |||
80 | } catch (e) { |
||
81 | |||
82 | alert(decryptionError); |
||
83 | console.log(e); |
||
84 | return false; |
||
85 | |||
86 | } |
||
190 |